package com.example.textview.recycleview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.example.textview.R;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class LinerAdapter extends RecyclerView.Adapter <LinerAdapter.LinearViewHoder>{

    private Context context;



    public  LinerAdapter(Context context)
    {
        this.context=context;
    }
    @NonNull
    @Override
    public LinerAdapter.LinearViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new LinearViewHoder(LayoutInflater.from(context ).inflate(R.layout.layout_linear_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull LinearViewHoder holder, final int position) {
        holder.textView.setText("Hello word!");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, "position:"+position, Toast.LENGTH_SHORT).show();
            }
        });
    }



    @Override
    public int getItemCount() {
        return 30;
    }

   class LinearViewHoder extends RecyclerView.ViewHolder{

        private TextView textView;
       public LinearViewHoder(@NonNull View itemView) {
           super(itemView);
           textView=itemView.findViewById(R.id.tv_title);
       }
   }
}
